package com.tanjor.common.redis;

import java.util.Arrays;
import org.springframework.data.redis.core.RedisTemplate;
import com.tanjor.common.redis.interfaces.RedisService;

/**
 * 封装redis缓存服务器服务接口
 */
public class RedisServiceImpl implements RedisService {
    
    public RedisTemplate<String, Object> redisTemplate;
    
	public RedisTemplate<String, Object> getRedisTemplate() {
		return redisTemplate;
	}
	
	@Override
	public void setCacheValue(String key, Object obj, long time) {
		// TODO Auto-generated method stub
		redisTemplate.opsForValue().set(key, obj, time);
	}

	@Override
	public <T> T getCacheValue(String key, Class<T> clazz) {
		// TODO Auto-generated method stub
		return (T) redisTemplate.boundValueOps(key).get();
	}

	@Override
	public void delCacheValue(String... key) {
		// TODO Auto-generated method stub
		redisTemplate.delete(Arrays.asList(key));
	}

	@Override
	public boolean isCacheExists(String key) {
		// TODO Auto-generated method stub
		return redisTemplate.hasKey(key);  
	}
    

	public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@Override
	public void setCacheValue(String key, Object obj) {
		// TODO Auto-generated method stub
		redisTemplate.opsForValue().set(key, obj);
	}
	 
}